package com.lncd.backend.dto;

import com.lncd.backend.model.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserDTO {
    private Long id;
    private String username;
    private String phone;
    private String password;
    private User.UserType userType;
    private String emergencyContact;
    private List<Long> relatedUserIds = new ArrayList<>();

    public static UserDTO fromEntity(User user) {
        UserDTO dto = new UserDTO();
        dto.setId(user.getId());
        dto.setUsername(user.getUsername());
        dto.setPhone(user.getPhone());
        dto.setUserType(user.getUserType());
        dto.setEmergencyContact(user.getEmergencyContact());
        
        if (user.getRelatedUsers() != null) {
            dto.setRelatedUserIds(user.getRelatedUsers().stream()
                    .map(User::getId)
                    .collect(Collectors.toList()));
        }
        
        return dto;
    }

    public static User toEntity(UserDTO dto) {
        User user = new User();
        user.setId(dto.getId());
        user.setUsername(dto.getUsername());
        user.setPhone(dto.getPhone());
        user.setPassword(dto.getPassword());
        user.setUserType(dto.getUserType());
        user.setEmergencyContact(dto.getEmergencyContact());
        
        return user;
    }
} 